package StringTest;

import java.util.Random;

public class test4 {
    public static void main(String[] args) {
        //1.将52个英文字母放入数组
        char[] arr=new char[52];
        char c1='A';
        char c2='a';
        for (int i = 0; i < arr.length; i++) {
            if(i<26){
                arr[i]=c1++;
            }else {
                arr[i]=c2++;
            }
            //System.out.println(arr[i]);
        }
        //2.随机取4位字母放入字符串
        String res="";
        Random r=new Random();
        for (int i = 0; i < 4; i++) {
            int Index = r.nextInt(arr.length);
            res=res+arr[Index];
        }
        //System.out.println(res);

        //3.随机一位数字放入最后一位
        res=res+r.nextInt(9);
        System.out.println(res);

        //4.将数字随机放入一位
        char[] charArray = res.toCharArray();
        //交换
        int num  = r.nextInt(res.length() - 1);
        char temp=charArray[charArray.length-1];
        charArray[charArray.length-1]=charArray[num];
        charArray[num]=temp;

        res=new String(charArray);
        System.out.println(res);
    }
}
